package v2

type ParserFunc func(body []byte,url string) ParseResult

// 通过函数， 构建一个解析器对象
type FuncParser struct {
	parser  ParserFunc
	name 	string
}

func (p *FuncParser) Parser(contents []byte,url string) ParseResult {
	return p.parser(contents,url)
}

func (p *FuncParser) Serialize() (name string,args interface{})  {
	return p.name,nil
}


func NewFuncParser(p ParserFunc,name string) *FuncParser {
	return &FuncParser{
		parser: p,
		name:   name,
	}
}


type NilParse struct {}

func (NilParse) Parse(contents []byte,url string) ParseResult {
	return ParseResult{}
}

func (NilParse) Serialize() (name string,args interface{}) {
	return "NilParse",nil
}


type ProfileParser struct {
	userName string
}

func (p *ProfileParser) Parse(contents []byte, url string) ParseResult {
	return ParseProfile(contents, url, p.userName)
}

func (p *ProfileParser) Serialize() (name string, args interface{}) {
	return "ProfileParser", p.userName
}

func NewProfileParser(name string) *ProfileParser {
	m := &ProfileParser{
		userName: name,
	}
	return m
}
